#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back
#define vec vector<int>

int read(){int x = 0,sgn = 1;char ch = getchar();for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);return x*sgn;}

const int N = 2e6+10;
const int mod = 998244353;

int n,m,a[N],b[N];
ll fac[N],inv[N];
ll f[110][110];

ll qp(ll x,int t){ll res=1;for(;t;t >>= 1,x = x * x % mod) if(t & 1) res=res*x%mod;return res;}

ll C(int x,int y){if(x < y || x < 0 || y < 0) return 0;return fac[x] * inv[y] % mod * inv[x - y] % mod;}

void init(int l){
	for(int i = (fac[0] = 1);i <= l;i++) fac[i] = fac[i-1] * i % mod; inv[l] = qp(fac[l],mod-2);
	for(int i = l - 1;i >= 0;i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll delt(){
	ll ans = 1;
	for(int i = 1;i <= m;i++){
		int j = i; for(;j <= m;j++) if(f[j][i]) break;
		if(j ^ i) ans = mod - ans,swap(f[i],f[j]);
		for(j = i + 1;j <= m;j++)
			while(f[j][i]){
				int t = f[j][i] / f[i][i];
				for(int k = i;k <= m;k++) f[j][k] = (f[j][k] + mod - f[i][k] * t % mod) % mod;
				if(!f[j][i]) break;
				ans = mod - ans; swap(f[i],f[j]);
			}
	}
	for(int i = 1;i <= m;i++) ans = ans * f[i][i] % mod;
	return ans;
}

void solve(){
	n = in,m = in;
	for(int i = 1;i <= m;i++) a[i] = in,b[i] = in;
	for(int i = 1;i <= m;i++)
		for(int j = 1;j <= m;j++)
			f[i][j] = C(b[j] - a[i] + n - 1,n - 1);
	printf("%lld\n",delt());
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	init(2000000);
	int T = in;
	while(T--) solve();
	return 0;
}
